//
//  LineTableViewHeaderView.swift
//  FrameProduct
//
//  Created by delegate on 2025/10/21.
//

import UIKit

class LineTableViewHeaderView: UIView {
    var sectionModel: NoteSectionModel = NoteSectionModel() {
        didSet {
            
        }
    }
    var headerViewDidTapActionBlock: ((NoteSectionModel) -> Void)?
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        
        let tap = UITapGestureRecognizer(target: self, action: #selector(headerViewDidTapAction))
        addGestureRecognizer(tap)
    }
    @objc private func headerViewDidTapAction() {
        headerViewDidTapActionBlock?(sectionModel)
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func setupUI() {
        addSubviews(iconImageView, titleLabel, speedLabel, arrowButton)
        iconImageView.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalTo(20)
            make.width.equalTo(33)
            make.height.equalTo(20)
        }
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(iconImageView.snp.right).offset(15)
            make.centerY.equalTo(iconImageView.snp.centerY)
            make.height.equalTo(21)
        }
        arrowButton.snp.makeConstraints { make in
            make.right.equalTo(-32)
            make.centerY.equalTo(titleLabel.snp.centerY)
            make.width.equalTo(12)
            make.height.equalTo(7)
        }
        speedLabel.snp.makeConstraints { make in
            make.right.equalTo(arrowButton.snp.left).offset(-20)
            make.centerY.equalTo(arrowButton.snp.centerY)
            make.height.equalTo(21)
        }
        
    }
    
    //=================================================================
    //                            lazy
    //=================================================================
    // MARK: - lazy
    private lazy var iconImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.backgroundColor = .purple
        return imageView
    }()
    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.text = "中国"
        label.textColor = .lxs.hex("#CCCCCC")
        label.font = .lxs.font(size: 14)
        return label
    }()
    private lazy var speedLabel: UILabel = {
        let label = UILabel()
        label.text = "10s"
        label.textColor = .lxs.hex("#43CF7C")
        label.font = .lxs.font(size: 14)
        return label
    }()
    private lazy var arrowButton: UIButton = {
        let button = UIButton(type: .custom)
        button.setImage(UIImage(named: "zhankai"), for: .normal)
        button.setImage(UIImage(named: "shouqi"), for: .selected)
        button.isUserInteractionEnabled = false
        return button
    }()
}
